<?php

namespace App\Library\Logic;

use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Follow\FollowPageRequest;
use App\Models\FollowModel;

class FollowLogic extends FollowModel
{
    /**
     * userPaging
     * @param BasePageRequest $request
     * @return array
     */
    public function userPaging(BasePageRequest $request): array
    {
        $builder = $this->newQuery()->leftJoin('auction_certification', 'auction_certification.user_id', 'follow.seller_id')
            ->orderByDesc('follow.created_at');
        return paginate(helpBuilder($builder, $request)->paginate($request->limit, [
            'store_name',
            'store_avatar_file_id',
            'follow.created_at',
        ]));
    }

    /**
     * sellerPaging
     * @param BasePageRequest $request
     * @return array
     */
    public function sellerPaging(BasePageRequest $request): array
    {
        $builder = $this->newQuery()->leftJoin('shop_user', 'shop_user.user_id', 'follow.user_id')
            ->orderByDesc('follow.created_at');
        return paginate(helpBuilder($builder, $request)->paginate($request->limit, [
            'user_nickname',
            'user_avatar',
            'follow.created_at',
        ]));
    }
}
